package com.eshop.we.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.eshop.we.favorite.dto.FavoriteDto;
import com.eshop.we.favorite.entity.Favorite;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * 用户书籍收藏表 Mapper 接口
 * </p>
 *
 * @author anonymity
 * @since 2018-07-06
 */
@Mapper
@Component
public interface FavoriteMapper extends BaseMapper<Favorite> {

    @Select(" select f.*,u.real_name,u.school_id,s.name as schoolName from favorite f left join user u on f.favorite_id=u.id " +
            " left join school s on u.school_id=s.id " +
            " where f.type=0 and  u.is_del=0 and f.user_id=#{userId}")
    List<FavoriteDto> selectUserBooks(@Param("userId")Integer userId);

    @Update("update favorite set is_del=1 where type=0 and favorite_id=#{favoriteId} and user_id=#{userId}")
    Integer  updateFavoriteStatus(@Param("favoriteId") Integer favoriteId,@Param("userId") Integer userId);

}
